package com.brtbeacon.demo.lot;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.brtbeacon.demo.lot.speech.SpeechEngine;

public class SpeechEngineActivity extends AppCompatActivity implements View.OnClickListener {

    private SpeechEngine speechEngine = null;

    private TextView tvEngineName;
    private EditText editContent;
    private Button btnPlay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_speech_engine);
        speechEngine = SpeechEngine.create(this);

        tvEngineName = findViewById(R.id.tv_engine_name);
        editContent = findViewById(R.id.edit_content);
        btnPlay = findViewById(R.id.btn_play);

        tvEngineName.setText(speechEngine.getName());
        btnPlay.setOnClickListener(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (speechEngine != null) {
            speechEngine.close();
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_play: {
                String content = editContent.getText().toString();
                if (!TextUtils.isEmpty(content)) {
                    speechEngine.speak(content);
                }
                break;
            }
        }
    }
}
